<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>两栋颜色不同且距离最远的房子</title>
</head>
<body>
  <script>
  var colors =[{
    house:'0',
    color:'blue'
  },
  {
    house:'1',
    color:'blue'
  },
  {
    house:'2',
    color:'blue'
  },
  {
    house:'3',
    color:'blue'
  },
  {
    house:'4',
    color:'blue'
  },
  {
    house:'5',
    color:'red'
  },
  {
    house:'6',
    color:'blue'
  }]



  var maxDistance = function(colors) {
    const n = colors.length
    let max = 0
    for (let i = 0; i < n - 1; i++) {
        for (let j = i + 1; j < n; j++) {
            let dis = Math.abs(i - j)
            if (colors[i].color !== colors[j].color) {
                max = Math.max(max, dis)
            }
        }
    }
    return max
  };
  console.log(maxDistance(colors));
  </script>
</body>
</html>